﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace D20.Entities.Characters
{
    /// <summary>
    /// A creature's skills.
    /// </summary>
    public class SkillSet
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SkillSet"/> class.
        /// </summary>
        public SkillSet()
        {
            Skills = new List<Skill>();
        }
        /// <summary>
        /// Gets the skills.
        /// </summary>
        /// <value>The skills.</value>
        public List<Skill> Skills { get; private set; }
    }
    /// <summary>
    /// A skill.
    /// </summary>
    public struct Skill
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Skill"/> struct.
        /// </summary>
        /// <param name="skillType">Type of the skill.</param>
        public Skill(SkillType skillType)
        {
            this.skillType = skillType;
            proficiency = 0;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Skill"/> struct.
        /// </summary>
        /// <param name="skillType">Type of the skill.</param>
        /// <param name="proficiency">The proficiency.</param>
        public Skill(SkillType skillType, int proficiency)
        {
            this.skillType = skillType;
            this.proficiency = proficiency;
        }

        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(Skill left, Skill right)
        {
            return left.Proficiency == right.Proficiency && left.SkillType == right.SkillType;
        }
        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left.</param>
        /// <param name="right">The right.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(Skill left, Skill right)
        {
            return !(left.Proficiency == right.Proficiency && left.SkillType == right.SkillType);
        }

        /// <summary>
        /// Indicates whether this instance and a specified object are equal.
        /// </summary>
        /// <param name="obj">Another object to compare to.</param>
        /// <returns>
        /// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is Skill)
            {
                Skill s = (Skill)obj;
                return SkillType == s.SkillType && Proficiency == s.Proficiency;
            }
            return false;
        }
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>
        /// A 32-bit signed integer that is the hash code for this instance.
        /// </returns>
        public override int GetHashCode()
        {
            return SkillType.GetHashCode() ^ Proficiency<< 16;
        }
        /// <summary>
        /// Gets or sets the type of skill.
        /// </summary>
        /// <value>The type.</value>
        public SkillType SkillType { get { return skillType; } set { skillType = value; } }

        /// <summary>
        /// Gets or sets the proficiency.
        /// </summary>
        /// <value>The proficiency.</value>
        public int Proficiency { get { return proficiency; } set { proficiency = value; } }
        private int proficiency;
        private SkillType skillType;
    }

    /// <summary>
    /// The different types of skills.
    /// </summary>
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1008:EnumsShouldHaveZeroValue", Justification = "Not logical here.")]
    public enum SkillType
    {
        /// <summary>
        /// Search
        /// </summary>
        Search,
        /// <summary>
        /// Listen.
        /// </summary>
        Listen
    }
}
